BookingDonation = function() {
	bookingDonationThis = this;
	//클래스에서 사용하는 this
	bookingDonationThis.listCount = 1;
	//서버에 보내는 리스트 카운트
	bookingDonationThis.currPageNo = 1;
	//서버에 보내는 현재 페이지 번호
	bookingDonationThis.donationGetListCount = 10;
	//화면에 리스트를 몇개씩 뿌려줄지 결정하는 변수
	bookingDonationThis.donationListCounter = 10;
	//리스트를 몇개씩 불러올지 결정한 후 더보기 버튼을 눌렀을 때 noticeGetListCount + donationListCounter 를 이용해서 한번더 10개를 불러올수 있게 하기 위한 변수
	bookingDonationThis._HTMLDom = null;
	//dom 으로 사용하는 클래스 변수
}
BookingDonation.prototype = {
	donationMainReserveList : function() {
		var mj = new MJson();
		var cm = new ConnectionManager();

		mj.putPub(MJson.PUB.SID, "DR001");
		mj.putPub(MJson.PUB.SERVICENAME, "DonationMainReservList");

		mj.putPub(MJson.PUB.LISTCOUNT, bookingDonationThis.listCount);
		mj.putPub(MJson.PUB.CURRPAGENO, bookingDonationThis.currPageNo);
		mj.putClient("userid", document.globalObj.LOGIN_DATA.userId);
		console.log("request : " + mj.getJsonString());

		cm.requestGet(mj.getJsonString(), function(jsonData) {
			//console.log("성공 :: 통신");
			console.log("jsonData :: " + JSON.stringify(jsonData));
			if (mj.checkServiceResult(jsonData)) {
				console.log("success :: " + JSON.stringify(jsonData));
				bookingDonationThis._HTMLDom.donation_btn.hide();
				//더보기 버튼 숨김
				//console.log('donationMainReserveList :: 성공');
				if (jsonData.msp.contents.items == undefined) {
					if (bookingDonationThis.currPageNo == 1) {
						bookingDonationThis._HTMLDom.list_layer.append(bookingDonationThis._HTMLDom.list_noItem.clone());
						//신청한 자선예약 없습니다.
					}
					console.log("::::재귀함수 종료:::::");
					return;
				}
				console.log(bookingDonationThis.currPageNo + "번째 데이터 로드");
				//------- UI Display -------//

				var list_layer = bookingDonationThis._HTMLDom.list_layer;
				var list_item = bookingDonationThis._HTMLDom.list_item;

				list_item.attr("id", 'donation_contents' + bookingDonationThis.currPageNo);

				list_layer.append(list_item.clone());

				var $donationContents = '#donation_contents' + bookingDonationThis.currPageNo;
				var donationDateTime = $($donationContents).find('dt:first > p:eq(0)');
				var donationTime = '<em>신청기간  :</em>' + jsonData.msp.contents.items.startDt + '~' + jsonData.msp.contents.items.endDt;
				donationDateTime.html(donationTime);

				var donationPublicDate = $($donationContents).find('dt:first > p:eq(1)');
				var publicDate = (jsonData.msp.contents.items.publicDate ? jsonData.msp.contents.items.publicDate : jsonData.msp.contents.items.reservDate)
				var publicDate = '<em>당첨자발표  :</em>' + publicDate;
				donationPublicDate.html(publicDate);

				var donationTitle = $($donationContents).find('h5');
				var title = jsonData.msp.contents.items.courseInfoNm;
				donationTitle.html(title);

				var donationReserveDate = $($donationContents).find('li:eq(0)');
				reservDate = '<em>라운드날짜</em>' + jsonData.msp.contents.items.reservDate + '(' + jsonData.msp.contents.items.bookingDay + ')';
				donationReserveDate.html(reservDate);

				var donationTeaTime = $($donationContents).find('li:eq(1)');
				var teaTime = '<em>티타임</em>' + jsonData.msp.contents.items.bookingTime;
				donationTeaTime.html(teaTime);

				var donationGreenFee = $($donationContents).find('li:eq(2)');
				var greenFee = '<em>1인 그린피</em><mark>' + jsonData.msp.contents.items.donatePrice + '</mark>';
				donationGreenFee.html(greenFee);

				var donationApplyCnt = $($donationContents).find('dd:first > div:eq(1) > p:eq(0)');
				var applyCnt = '참여 :<mark>' + jsonData.msp.contents.items.applyCnt + '</mark>명';
				donationApplyCnt.html(applyCnt);

				var donationBtnAsk = $($donationContents).find('dd:first > div:eq(1) > p:eq(1)');
				var donationTextIng = $($donationContents).find('dd:first > div:eq(1) > p:eq(2)');
				var donationBtnComplete = $($donationContents).find('dd:first > div:eq(1) > p:eq(3)');
				var donationTextClose = $($donationContents).find('dd:first > div:eq(1) > p:eq(4)');
				var donationBtnCheck = $($donationContents).find('dd:first > div:eq(1) > p:eq(5)');
				var donationTextEnd = $($donationContents).find('dd:first > div:eq(1) > p:eq(6)');
				//TODO jsonData.msp.contents.items.resrvStatus 에 따른 상황 값을 설정하는 부분에서 명확하지 않은 부분이 있음 기획 확인 후 작업
				switch(jsonData.msp.contents.items.resrvStatus) {
					case "C":
						{
							if (jsonData.msp.contents.items.myStatus == 'S') {
								donationBtnAsk.find('a').bind('click', function(event) {
									document.globalObj.DONATION_DATA.donation_seq = jsonData.msp.contents.items.reserveSeq;
									$.mobile.changePage('donation_view.html');
								});
								donationBtnAsk.hide();
								donationTextIng.hide();
								donationBtnComplete.show();
								donationTextClose.hide();
								donationBtnCheck.hide();
								donationTextEnd.hide();
								donationTextEnd.hide();
							} else {
								donationBtnAsk.find('a').bind('click', function(event) {
									document.globalObj.DONATION_DATA.donation_seq = jsonData.msp.contents.items.reserveSeq;
									$.mobile.changePage('donation_view.html');
								});
								donationBtnAsk.show();
								donationTextIng.hide();
								donationBtnComplete.hide();
								donationTextClose.hide();
								donationBtnCheck.hide();
								donationTextEnd.hide();
								donationTextEnd.hide();
							}
						}
						break;

					case "E":
						if (jsonData.msp.contents.items.myStatus == 'S') {
							donationBtnAsk.hide();
							donationTextIng.hide();
							donationBtnComplete.hide();
							donationTextClose.show();
							donationBtnCheck.find('a').bind('click', function(event) {
								document.globalObj.DONATION_DATA.donation_seq = jsonData.msp.contents.items.reserveSeq;
								$.mobile.changePage('donation_view.html');
							});
							donationBtnCheck.show();
							donationTextEnd.hide();
							donationTextEnd.hide();
						} else {
							donationBtnAsk.hide();
							donationTextIng.hide();
							donationBtnComplete.hide();
							donationTextClose.show();
							donationBtnCheck.find('a').bind('click', function(event) {
								document.globalObj.DONATION_DATA.donation_seq = jsonData.msp.contents.items.reserveSeq;
								$.mobile.changePage('donation_view.html');
							});
							donationBtnCheck.hide();
							donationTextEnd.hide();
							donationTextEnd.hide();
						}
						break;

					case "F":
					default :
						donationBtnAsk.hide();
						donationTextIng.hide();
						donationBtnComplete.hide();
						donationTextClose.hide();
						donationBtnCheck.hide();
						donationTextEnd.hide();
						donationTextEnd.show();
						break;
				}

				//--------------------------//
				bookingDonationThis.currPageNo++;
				//재귀함수 호출
				if (bookingDonationThis.currPageNo <= bookingDonationThis.donationGetListCount) {
					//재귀함수 호출 전 다음번 리스트를 지정하기 위한 연산
					bookingDonationThis.donationMainReserveList();
					//조건을 만족할때 까지 재귀함수 실행
				} else {
					bookingDonationThis._HTMLDom.donation_btn.show();
				}
			} else {
				console.log('donationMainReserveList :: 실패');
			}
		}, function(e) {
			console.log("실패 :: 통신");
		});
	},
	onPageShow : function() {
		bookingDonationThis.listCount = 1;
		bookingDonationThis.currPageNo = 1;
		//-------DOM 객체 설정
		var list_layer = $('#donation_list');
		var list_noItem = list_layer.find('dl:eq(0)');
		var list_item = list_layer.find('dl:eq(1)');
		var donation_btn = $('#donation_btn');

		this._HTMLDom = {
			// 리스트 레이어
			"list_layer" : list_layer,
			// 리스트 아이템
			"list_item" : list_item,
			"date_title" : list_item.find('dt:first'),
			"item_contents" : list_item.find('dd:first'),
			"donation_btn" : donation_btn
		};
		list_layer.empty();
		this._HTMLDom.donation_btn.hide();
		//-------DOM 객체 설정
		bookingDonationThis.donationMainReserveList();
		$("#goMyDonation").bind('click', function(event) {
			$.mobile.changePage('donation_my.html');
			//내 자선예약 페이지 이동
		});
		this._HTMLDom.donation_btn.bind('click', function(event) {
			console.log('test');
			bookingDonationThis.donationGetListCount = bookingDonationThis.donationListCounter + bookingDonationThis.donationGetListCount;
			bookingDonationThis.donationMainReserveList();
			//내 자선예약 페이지 이동
		});
		$("#donation_reserv_select").bind('change', function(event) {
			//자동 로그인 바인드
			console.log($(this).val());
			switch ($(this).val()) {
				case "0":
					console.log('++++');
					$.mobile.changePage('calendar.html');
					break;

				case "1":
					break;

				case "2":
					break;
			}
		});
	},
}
